/**
 * 作者：陈圳佳
 * 日期：2015/8/12
 */
$(function () {
    var $date = $("#show-date");
    $date.text(getDate());
    setInterval(function () {
        $date.text(getDate());
    }, 60000);
});
(function (angular) {
    angular.module("manage", [], function ($compileProvider) {
        $compileProvider.directive('compile', function ($compile) {
            return function (scope, element, attrs) {
                scope.$watch(
                    function (scope) {
                        return scope.$eval(attrs.compile);
                    },
                    function (value) {
                        element.html(value);
                        $compile(element.contents())(scope);
                    }
                );
            };
        });
    }).controller("LoginOutController", function ($scope, $http) {
        $scope.outObject = {};
        $scope.out = function () {
            $('#load-dialog').modal('show');
            var url = $scope.outObject.ctx + "/sign/out/";
            $http.delete(url).success(function (resp) {
                setTimeout(function () {
                    if (resp.status)
                        location.replace(resp.url);
                }, 200);
            }).error(function (resp) {
                showErrorMessage("出错了,信息:" + resp.msg);
            });
        };
    }).controller("Edit", function ($scope, $http) {
        $scope.submit = function () {
            var values = $scope.formValue;
            var config = $scope.formConfig;
            var $p;
            if (config.method == 'PUT') {
                $p = $http.put(config.action,
                    JSON.stringify(values));
            } else
                $p = $http.post(config.action,
                    JSON.stringify(values));
            $p.success(function (resp) {
                    if (resp.status) {
                        $('#edit-dialog').modal('hide');
                        showMessage(resp.msg);
                    } else {
                        if (resp.url != undefined) {
                            location.replace(resp.url);
                        }
                        showErrorMessage("失败了！错误信息：" + resp.msg);
                    }
                    globalObj.successCall(resp);
                }
            );
            return false;
        };
    }).controller("ListCtrl", function ($scope, $http) {
        $scope.del = function (url) {
            $http.delete(url).success(function (resp) {
                if (resp.status) {
                    $.pjax({url: location.href, container: '#content'});
                    showMessage(resp.msg);
                } else {
                    if (resp.url != undefined) {
                        location.replace(resp.url);
                    }
                    showErrorMessage("失败了！错误信息：" + resp.msg);
                }
            })
        }
    })
})(window.angular);